import React from 'react';
import { Button, Icon } from 'antd';
import styles from './index.less';
import { PREVIEW_TYPE } from './constant';

export default function FileShowView(props) {
    const getFileType = fileName =>
        fileName
            .split('.')
            .pop()
            .toLowerCase();
    const { handlePreview = () => {}, showPreview = true, showDownLoad = true, item = { url: '' } } = props;
    return (
        <>
            <span className={styles.detailName}>
                <Icon type="paper-clip" className={styles.pr10} />
                {item.name}
            </span>
            <div className={styles.diplomaDownload}>
                {showPreview && PREVIEW_TYPE.includes(getFileType(item.name)) && (
                    <Button icon="eye" type="link" onClick={() => handlePreview(item)}></Button>
                )}
                <span className={styles.splitLine} />
                {showDownLoad && <Button icon="download" type="link" href={item.url}></Button>}
            </div>
        </>
    );
}
